<?php namespace Admin\Controller;

/**
 * 货品管理
 * @author  hdxj <[<email address>]>
 */
class ProductController extends AuthController{

protected $db;
public function __init(){
	$this->db= new \Admin\Model\Product;
}
	//根据商品ID获取货品列表
	public function index()
	{
		if(IS_POST){
			if($this->db->addProduct())
			{
				$this->success('添加成功');
			}
			else
			{
				$this->error($this->db->getError());
			}
		}
		else{
			$goods_id = $_GET['goods_id'];
			//获取商品类型属性
			$attr = Db::table('shop_goods_attr ga')
			->join('shop_attr a','ga.attr_id','=','a.attr_id')
			->where('ga.goods_id',$goods_id)
			->where('a.attr_type',2)
			->groupBy('ga.attr_id')->get();
			View::with('attr',$attr);
			//获取商品的所有属性
			$goodsAttr=Db::table('shop_goods_attr')->where('goods_id',$goods_id)->get();
			View::with('goodsAttr',$goodsAttr);

			//读取货品列表
			View::with('product',$this->db->getProduct($_GET['goods_id']));
			View::make();
		}
	}

	//修改货品数量
	public function edit()
	{
		if($this->db->edit())
		{
			View::ajax(array('code'=>0,'message'=>'修改成功'));
		}
		else
		{
			View::ajax(array('code'=>1,'message'=>'修改失败'));
		}
	}
}











